//
//  HotcityView.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/1/3.
//  Copyright © 2016年 game. All rights reserved.
//

#import "HotcityView.h"
#import "HotCity.h"

@implementation HotcityView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        _title = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 100, 30)];
        [self addSubview:_title];
    }
    return self;
}

-(void)setCityAry:(NSArray *)cityAry{
   
    for (int i = 0; i<cityAry.count; i++) {
      
        UIButton *bnt = [UIButton buttonWithType:UIButtonTypeSystem];
        [bnt setTitle:cityAry[i]forState:UIControlStateNormal];
        [bnt setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        bnt.tag = 10 +i;
        [bnt addTarget:self action:@selector(didSender:) forControlEvents:UIControlEventTouchUpInside];
        
        bnt.backgroundColor = [UIColor whiteColor];
        CGFloat xd = 10;//横间隙；
        CGFloat yd = 10;//竖间隙
        
        CGFloat width = (self.frame.size.width+5)/5;
        CGFloat hight = (150-yd)/5;
        
        int row = i/4;//i在哪一行
        int colum = i%4;//i在哪一列；
        
        CGFloat x = xd+(width + xd)*colum;
        CGFloat y = yd+(hight+yd)*row+H(_title);
        
        bnt.frame = CGRectMake(x,y, width, hight);
        
        bnt.layer.borderWidth = 0.6;
        bnt.layer.borderColor = textcolor.CGColor;
        bnt.layer.masksToBounds = YES;
        
        [self addSubview:bnt];
    }
}

-(void)didSender:(UIButton *)sender{
    
    if (_MyBlock) {
        _MyBlock(sender);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
